package com.example.tms.mapper;

import com.example.tms.bean.RoleInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 角色信息
 */
@Repository
public interface RoleMapper extends JpaRepository<RoleInfo,String>, JpaSpecificationExecutor<RoleInfo> {

    RoleInfo findByJsidAndSfcz(String jsid, Boolean sfcz);

    @Query(value = "select * from role_info where jsmc = ?1 and sfcz = true", nativeQuery = true)
    RoleInfo findByJsmcAndSfcz(String jsmc);

    List<RoleInfo> findBySfcz(Boolean sfcz);

    //删除线路信息（假删除 线路id）
    @Query(value = "update role_info set sfcz = false where jsid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void DeleteByJsid(String jsid);

    //删除线路信息（假删除 线路id）
    @Query(value = "update role_info set jsmc = ?2 where jsid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void modifyMc(String jsid ,String jsmc);

}
